{%insert header.tpl%}
<script type="text/javascript" src="{% $THEME_URL %}/js/tiny_mce/jquery.tinymce.js"></script>
{%insert top.tpl%}
<h3>
{%iterate Path as url > title%}
<a href="{% q < url %}">{% i < title %}</a>&nbsp;|&nbsp;
{%iterate%}
{% i <  Title %}&nbsp;|&nbsp;
{%with ModelItem%}
{% context %}
{%endwith%}
</h3>
<script language="javascript" type="text/javascript">
	function show_tab(tab){
		var t = $(tab);
		t.parent().next().children().hide();
		$("#"+tab.id.replace("_tab","")+"_pane").show();
		t.parent().children().removeClass("active");
		t.addClass("active");
		$.cookie("<?php echo $this->PAGE->Name(); ?>_"+t.parent().attr("id"),t.attr("id"));
	}

	$(document).one("ready",function(){
		$(".tabs").each(function(){
			cv = $.cookie("<?php echo $this->PAGE->Name(); ?>_"+this.id);
			if (cv)
				show_tab($("#"+cv)[0]);
			else
				show_tab($(".tab",this)[0]);
		});
	});
</script>
<link type="text/css" href="{% $THEME_URL %}/css/product.css" rel="stylesheet" />
<div id="main_tabs" class="tabs">
<span id="product_tab" class="tab" onclick="javascript:show_tab(this);">Товар</span>
<span id="images_tab" class="tab" onclick="javascript:show_tab(this);">Изображения</span>
<span id="discount_tab" class="tab" onclick="javascript:show_tab(this);">Скидки</span>
<span id="content_tab" class="tab" onclick="javascript:show_tab(this);">Страница</span>
{%iterate Modules as mn > m%}
<span id="{%mn%}_tab" class="tab" onclick="javascript:show_tab(this);">{% i < Caption %}</span>
{%iterate%}
</div>
<div class="panes">
<div class="pane" id="product_pane">
<script language="javascript" type="text/javascript">
	function new_article_dlg(){
		var $dlg = $("#new-article-dlg");
		$dlg.show();
		$dlg.css('left',Math.round(($(document).width() - $dlg.width())/2)).css('top',Math.round(($(document).height() - $dlg.height())/2));
	}
</script>
<div id="new-article-dlg" style="display:none;">
	<form method="post" enctype="multipart/form-data">
		<input type="hidden" name="method" value="CreateArticle" />
		<div class="article">
			{%assign _artprop_ ArticleProperties < DummyArticle%}
			{%iterate _artprop_ as p%}
				<div class="field{%odd%} odd{%endodd%}">{%insert property.tpl%}</div>
			{%iterate%}
		</div>	
		<div class="btn-holder bottom-toolbar">	
		<button type="button" class="submit-btn" onclick="javascript:submit();return false;">{% i < `Create` %}</button>
		<button type="button" class="cancle-btn" onclick="javascript:$(&quot;#new-article-dlg&quot;).hide();return false;">{% i < `Cancel` %}</button>
		</div>
	</form>
</div>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="method" value="Save" />
<div class="btn-holder top-toolbar">
	<button type="button" class="submit-btn" onclick="javascript:submit();return false;">{% i <  SaveActionTitle %}</button>
	{%if ListUrl%}
	<button type="button" class="cancel-btn" onclick="javascript:window.location.href=&quot;{% q < ListUrl %}&quot;;return false;">{% i <  BackActionTitle %}</button>
	{%endif%}
	<button type="button" class="add-article" onclick="javascript:new_article_dlg();return false;">Добавить артикул</button>
</div>
<div class="pane-contents">
{%iterate NomenclatureProperies as p%}
<div class="field{%odd%} odd{%endodd%}">
	{%insert property.tpl%}
</div>
{%iterate%}
<fieldset class="stock-data">
{%with ModelItem %}
{%with Articles%}
<legend>{% i < `Stock` %}({%ItemCount%})</legend>
{%endwith%}
{%iterate Articles as article%}
<div class="article">
<div class="delete-link-holder">
<a class="button delete-link" href="{% q < ItemDeleteUrl < context %}"><button type="button" title="{% i < `Delete` %}"></button></a>
</div>
	{%assign _artprop_ ArticleProperties < context%}
	{%iterate _artprop_ as p%}
		<div class="field{%odd%} odd{%endodd%}">{%insert property.tpl%}</div>
	{%iterate%}
</div>
{%iterate%}
{%endwith%}
</fieldset>
</div>
</form>
</div>
<div class="pane" id="images_pane" style="display:none;">
<script type="text/javascript" language="javascript">
	function add_img_fld(){
		$("#img_add_area").append('<div><input class="add_img_fld" name="addimages['+$("input.add_img_fld").length+']" type="file"/><a href="#" onclick="javascript:add_img_fld(this);return false;">еще...</a></div>');
	}
</script>
{%with ModelItem%}
<form class="editor" method="post" enctype="multipart/form-data">
<input type="hidden" name="method" value="EditImages" />
<fieldset id="img_add_area">
<legend>Добавить изображения</legend>
<div><input class="add_img_fld" name="addimages[0]" type="file"/><a href="#" onclick="javascript:add_img_fld(this);return false;">еще...</a></div>
</fieldset>
<table id="imgs">
{%iterate Images as im%}
<tr>
	<td>
		{%with TinyThumbnail%}
		<a class="imageloader" href="{% q < GetLink %}"><img src="{% q < GetThumbnailLink %}" height="40" /></a>
		{%endwith%}
	</td>
	<td><textarea name="imagesdesc[{% ItemId %}]">{% q < Description %}</textarea></td>
	<td><input type="text" name="imagesorder[{% ItemId %}]" value="{% OrderNumber %}" /></td>
	<td><input type="checkbox" name="deleteimages[{% ItemId %}]" />Удалить</td>
</tr>
{%iterate%}
</table>
<div class="btn-holder"><button type="submit">{% i < `Save` %}</button></div>
</form>
{%endwith%}
</div>
<div class="pane" id="discount_pane" style="display:none;">
{%assign __discounts__ Discounts%}
{%with ModelItem%}
<div>Артикул:<select onchange="javascript:show_discounts(this.value);">
<option value="all">все</option>
{%iterate Articles as a%}
<option value="{% ItemId %}">{% context %}</option>
{%iterate%}
</select>
</div>
{%assign __suffix__ `all`%}
{%insert product_discount.tpl%}
{%iterate Articles as a%}
{%assign __suffix__ ItemId%}
{%insert product_discount.tpl%}
{%iterate%}
{%endwith%}
<script type="text/javascript">
function show_discounts(suffix){
	$("form.discounts").hide();
	$("#dsc_"+suffix).show();
}

show_discounts('all');
</script>
</div>
<div class="pane" id="content_pane">
{%if ItemPage%}
<form class="editor" method="post" enctype="multipart/form-data">
<input type="hidden" name="method" value="SavePage" />
<table class="page-section">
	<tr>
	<td>
{%with ItemPage%}
	<div class="page-info">
	<div><span class="label">Заголовок страницы</span><input class="property-value" type="text" name="pp[Title]" value="{@% q < Title %}" /></div>
	<div><span class="label">Имя для ссылок</span><input class="property-value" type="text" name="pp[Slug]" value="{% q < Slug %}" /></div>
	<div><span class="label">Опубликован</span><input class="property-value" type="checkbox" name="pp[IsPublished]"{%if IsPublished%} checked{%endif%} /></div>
	<div>
		<span class="label">Ссылка на страницу витрины</span>
		<a id="frontend-link"></a>
	</div>
	<div>
	<div id="page_texts" class="tabs">
	<span id="long_desc_tab" class="tab" onclick="javascript:show_tab(this);">Описание</span>
	<span id="short_desc_tab" class="tab" onclick="javascript:show_tab(this);">Краткое описание</span>
	<span id="meta_tab" class="tab" onclick="javascript:show_tab(this);">Мета</span>
	</div>
	<div class="panes">
		<div class="pane" id="long_desc_pane"><textarea class="wysiwyg property-value" type="text" name="pp[PageContents]">{% q < PageContents %}</textarea></div>
		<div class="pane" id="short_desc_pane" style="display:none;"><textarea class="wysiwyg property-value" type="text" name="pp[Snippet]">{% q < Snippet %}</textarea></div>
		<div class="pane" id="meta_pane" style="display:none;">
			<div><span class="label">Мета-описание</span><textarea class="property-value" type="text" name="pp[Description]">{% q < Description %}</textarea></div>
			<div><span class="label">Ключевые слова</span><textarea class="property-value" name="pp[Keywords]">{% q < Keywords %}</textarea></div>
		</div>
	</div>
	</div>
{%endwith%}
	</td>
	<td>
	<span class="label">Категории:</span>
	<div class="page-categories">
	{%iterate Categories as cat%}
	{%insert integral.category_node.tpl%}
	{%iterate%}
	</div>
	</td>
	</tr>
	</table>
<div class="btn-holder bottom-toolbar"><button type="submit">{% i < `Save` %}</button></div>
{%else%}
<form class="editor" method="post" enctype="multipart/form-data">
<input type="hidden" name="method" value="PublishItem" />
<span class="label">{% i < `Categories`%}:</span>
	<div class="page-categories">
	{%iterate Categories as cat%}
	{%insert integral.category_node.tpl%}
	{%iterate%}
	</div>
	<div class="btn-holder bottom-toolbar"><button type="submit">{% i < `Publish` %}</button></div>
{%endif%}
</form>	
</div>
{%iterate Modules as mn > m%}
<div class="pane" id="{% mn %}_pane">
{%widget mn%}
</div>
{%iterate%}
</div>
<script language="javascript">
	$(document).ready(function(){
		$.getJSON("{@%FrontProductUrlQuery%}",function(data){
			$("#frontend-link").text(data).attr('href',data);
        });       				
	});
</script>
{%insert formfields.tpl%}
{%insert footer.tpl%}
